package interviewusa;

import java.util.Arrays;

public class Solution1 {

    public static void main(String[] args) {
        Solution1 solution = new Solution1();
        System.out.println(Arrays.toString(solution.getSums(new int[]{1,2,3,4})));
        System.out.println(Arrays.toString(solution.getSums(new int[]{-1,1,0,-3,3})));
        System.out.println(Arrays.toString(solution.getSums(new int[]{-1,1,0,-3,0,1})));
    }
    public int[] getSums(int[] arr) {

        int[] ans = new int[arr.length];
        int total = 1;
        int zeroIndex = -1;
        for (int i = 0; i  < arr.length; i++) {
            if (arr[i] == 0) {
                if (zeroIndex != -1) {
                    return ans;
                }
                zeroIndex = i;
            } else {
                total = total * arr[i];
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if (zeroIndex != -1) {
                if (i == zeroIndex) {
                    ans[i] = total;
                } else {
                    ans[i] = 0;
                }
            } else {
                ans[i] = total / arr[i];
            }
        }
        return ans;
    }

}
}
